package com.iotproject.studyservice.controller;


import com.iotproject.commonutils.R;
import com.iotproject.studyservice.entity.StudyGrade;
import com.iotproject.studyservice.service.StudyGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 单词等级 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2023-04-05
 */
@RestController
@RequestMapping("/studyservice/study-grade")
public class StudyGradeController {

    @Autowired
    StudyGradeService studyGradeService;

    //插入英语等级
    @GetMapping("insertStudyGrade")
    public R insertStudyGrade() {
        StudyGrade studyGrade01 = new StudyGrade();
        studyGrade01.setName("四级英语");
        studyGrade01.setCover("https://s2.xptou.com/2023/04/05/642d0af0d6eb9.png");
        boolean save = studyGradeService.save(studyGrade01);
        if (save) {
            return R.ok();
        } else {
            return R.error();
        }

    }

    //获得等级列表
    @GetMapping("getStudyGradeList")
    public R getStudyGradeList() {
        List<StudyGrade> list = studyGradeService.list(null);
        return R.ok().data("list", list);
    }

}

